<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form enctype="multipart/form-data">
        <input id="file_id" type="file" name="file">
        <button id = "btn"type="button">按钮</button>
    </form>
    <script>
        document.querySelector("#btn").onclick=function(){
            var file = document.getElementById("file_id").files
            console.log(file)
        }
        //如果使用ajax提交图片，不可以直接写在对象当中，需要借助formData对象对数据进行包装
        //直接console，无论是否数据，formdata展示不变
        var formdata = new FormData()
        formdata.append("username", '老边') //设置数据
        console.log(formdata)
        username = formdata.get('username') //获取
        formdata.delete('username') //删除
        // username1 = formdata.get('username') //获取
        // console.log(username1,"username1")
        // console.log(username,"username")
        

    </script>
</body>
</html>